package com.ds.infrastructure.audit.common.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Map;

/**
 * 作用：
 *
 * @author WeiShaoying
 * @date 2020/7/27
 */
@Data
@Builder
@AllArgsConstructor
public class KbaBehavior implements Serializable {

    private static final long serialVersionUID = -8787739388515623734L;

    /**
     * 组织ID
     */
    private String groupId;

    /**
     * 门店ID
     */
    private String shopId;

    /**
     * 业务名称
     */
    @NotBlank(message = "bizName不能为空")
    @Size(max = 20, message = "bizName最大长度20个字符")
    private String bizName;

    /**
     * 业务数据的唯一标识
     */
    private String behaviorId;

    /**
     * 行为
     */
    @NotBlank(message = "action不能为空")
    @Size(max = 20, message = "action最大长度20个字符")
    private String action;

    /**
     * 行为详情
     */
    @Size(max = 500, message = "actionDetail最大长度500个字符")
    private String actionDetail;

    /**
     * 重要级别
     */
    private Integer priority = 10;

    /**
     * 用户Id
     */
    @NotBlank(message = "userId不能为空")
    private String userId;

    /**
     * 扩展信息json
     */
    @Size(max = 30, message = "extra最多允许30个元素")
    private Map<String, String> extra;

    /**
     * 创建时间戳
     */
    private Long createTime = System.currentTimeMillis();


    public KbaBehavior() {
    }

    /**
     * 简单静态构造方法
     *
     * @param bizName
     * @param action
     * @param userId
     * @return
     */
    public static KbaBehavior of(String bizName, String action, String userId) {
        KbaBehavior behavior = new KbaBehavior();
        behavior.setBizName(bizName);
        behavior.setAction(action);
        behavior.setUserId(userId);
        return behavior;
    }


    /**
     * @param bizName
     * @param behaviorId
     * @param action
     * @param userId
     * @return
     */
    public static KbaBehavior of(String bizName, String behaviorId, String action, String userId) {
        KbaBehavior behavior = new KbaBehavior();
        behavior.setBizName(bizName);
        behavior.setBehaviorId(behaviorId);
        behavior.setAction(action);
        behavior.setUserId(userId);
        return behavior;
    }

    /**
     * @param groupId
     * @param shopId
     * @param bizName
     * @param behaviorId
     * @param action
     * @param userId
     * @return
     */
    public static KbaBehavior of(String groupId, String shopId, String bizName, String behaviorId, String action, String userId) {
        KbaBehavior behavior = new KbaBehavior();
        behavior.setGroupId(groupId);
        behavior.setShopId(shopId);
        behavior.setBizName(bizName);
        behavior.setBehaviorId(behaviorId);
        behavior.setAction(action);
        behavior.setUserId(userId);
        return behavior;
    }

    /**
     * 全的静态构造
     *
     * @param groupId
     * @param shopId
     * @param bizName
     * @param behaviorId
     * @param action
     * @param actionDetail
     * @param userId
     * @param extra
     * @param priority
     * @return
     */
    public static KbaBehavior of(String groupId, String shopId, String bizName, String behaviorId, String action, String actionDetail, String userId, Map<String, String> extra, Integer priority) {
        KbaBehavior behavior = new KbaBehavior();
        behavior.setGroupId(groupId);
        behavior.setShopId(shopId);
        behavior.setBizName(bizName);
        behavior.setBehaviorId(behaviorId);
        behavior.setAction(action);
        behavior.setUserId(userId);
        behavior.setActionDetail(actionDetail);
        behavior.setExtra(extra);
        behavior.setPriority(priority);
        return behavior;
    }

}
